home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  10KB  |  407 lines

  1. /* PACKAGE_DATA_DIR "/examples" to get path of the files */
  2. #include "ewl_test.h"
  3.  
  4. static Ewl_Widget     *main_text;
  5.  
  6. void
  7. __close_main_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  8.                 void *user_data __UNUSED__)
  9. {
  10.     ewl_widget_destroy(w);
  11.     ewl_main_quit();
  12. }
  13.  
  14. static void
  15. __realize_main_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  16.                     void *user_data __UNUSED__)
  17. {
  18.     printf("Main window realized with theme_object %p\n", w->theme_object);
  19. }
  20.  
  21. static void
  22. __fill_main_text(Ewl_Widget * w __UNUSED__, void *ev_data __UNUSED__,
  23.                     void *user_data)
  24. {
  25.         FILE *file;
  26.     struct stat buf;
  27.     char *str;
  28.     char *filename;
  29.     
  30.     filename = (char *)malloc (sizeof (char)*(strlen (PACKAGE_DATA_DIR) +
  31.                           strlen ("/examples/") + 
  32.                           strlen ((char *)user_data) + 1));
  33.     sprintf (filename, "%s/examples/%s", PACKAGE_DATA_DIR, (char *)user_data);
  34.  
  35.     file = fopen (filename, "r");
  36.     if (file)
  37.       {
  38.         stat (filename, &buf);
  39.         str = (char*)malloc (sizeof (char)*buf.st_size + 1);
  40.         
  41.         fread(str, buf.st_size, 1, file);
  42.         str[buf.st_size] = '\0';
  43.         ewl_text_text_set (EWL_TEXT (main_text), str);
  44.             free(str);
  45.       }
  46.     free (filename);
  47. }
  48.  
  49. int
  50. main(int argc, char **argv)
  51. {
  52.     int             i;
  53.     Ewl_Widget     *main_win;
  54.     Ewl_Widget     *main_box;
  55.     Ewl_Widget     *main_tree;
  56.     Ewl_Widget     *main_area;
  57.         /* Ewl_Widget     *separator; */
  58.     Ewl_Widget     *prow;
  59.     static test_set       tests[] = {
  60.         {
  61.             "Border",
  62.                __create_border_test_window,
  63.                "ewl_border_test.c", 
  64.             "Defines the Ewl_Border class for displaying\n"
  65.                 "a container with a label."
  66.         },
  67.         {
  68.             "Box",
  69.             __create_box_test_window,
  70.             "ewl_box_test.c",
  71.             "Defines the Ewl_Box class used for\n"
  72.                 "laying out Ewl_Widget's in a horizontal\n"
  73.                 "or vertical line."
  74.         },
  75.         {
  76.             "Button",
  77.                __create_button_test_window,
  78.                "ewl_button_test.c",
  79.             "The button class is a basic button\n"
  80.                 "with a label. This class inherits from\n"
  81.                 "the Ewl_Box to allow for placing any\n"
  82.                 "other widget inside the button."
  83.         },
  84.         {
  85.             "Calendar",
  86.             __create_calendar_test_window,
  87.             "ewl_calendar_test.c",
  88.             "Defines a calendar widget."
  89.         },
  90.         {
  91.             "ColorDialog",
  92.             __create_colordialog_test_window,
  93.             "ewl_colordialog_test.c",
  94.             "Defines a dialog with a color picker."
  95.         },
  96.         {
  97.             "ColorPicker",
  98.             __create_colorpicker_test_window,
  99.             "ewl_colorpicker_test.c",
  100.             "Defines a color picker."
  101.         },
  102.         {
  103.             "Combo",
  104.               __create_combo_test_window,
  105.               "ewl_combo_test.c",
  106.             "Defines a combo box used internally.\n"
  107.                 "The contents on the box are not drawn\n"
  108.                 "outside of the Evas."
  109.         },
  110.                 {
  111.                         "DatePicker",
  112.                         __create_datepicker_test_window,
  113.                         "ewl_datepicker_test.c",
  114.                         "Defines a datepicker widget."
  115.                 },
  116.         {
  117.             "Dialog",
  118.                __create_dialog_test_window,
  119.                "ewl_dialog_test.c",
  120.             "Defines a dialog window."
  121.         },
  122.         {
  123.             "Entry",
  124.               __create_entry_test_window,
  125.               "ewl_entry_test.c",
  126.             "Defines the Ewl_Entry class to allow\n"
  127.                 "for single line editable text.",
  128.         },
  129.         {
  130.             "Freebox",
  131.             __create_freebox_test_window,
  132.             "ewl_freebox_test.c",
  133.             "The freebox is used for a more free layout system\n"
  134.                 "then the other containers",
  135.         },
  136.         {
  137.             "Filedialog",
  138.             __create_filedialog_test_window,
  139.             "ewl_filedialog_test.c",
  140.             "The filedialog is intended to be used\n"
  141.                 "for a simple file chooser.",
  142.         },
  143.         {
  144.             "Filedialog MultiSelect",
  145.                    __create_filedialog_multi_test_window,
  146.                    "ewl_filedialog_multi_test.c",
  147.             "The filedialog with multiple selections enabled",
  148.         },
  149.         {
  150.             "Floater",
  151.                 __create_floater_test_window,
  152.                 "ewl_floater_test.c",
  153.             "Defines a widget for layering above other\n "
  154.                 "widgets in EWL's drawing area, with\n"
  155.                 "the ability to follow the movement of\n"
  156.                 "another widget."
  157.         },
  158.                 {
  159.                         "Icon",
  160.                         __create_icon_test_window,
  161.                         "ewl_icon_test.c",
  162.                         "Provides a widget for displaying an icon"
  163.                 },
  164.                 {
  165.                         "Iconbox",
  166.                         __create_iconbox_test_window,
  167.                         "ewl_iconbox_test.c",
  168.                         "Provides a widget for displaying icons\n"
  169.                                 "in an arranged grid, or freeform,\n"
  170.                 "with callback and label editing facilities.",
  171.                 },
  172.         {
  173.             "Image",
  174.               __create_image_test_window,
  175.               "ewl_image_test.c",
  176.             "Provides a widget for displaying evas\n"
  177.                 "loadable images, and edjes.",
  178.                },
  179.         {
  180.             "IMenu",
  181.               __create_imenu_test_window,
  182.               "ewl_imenu_test.c",
  183.             "Defines a menu used internally. The\n"
  184.                 "contents on the menu are not drawn\n"
  185.                 "outside of the Evas."
  186.         },
  187.         {
  188.             "Menu",
  189.              __create_menu_test_window,
  190.              "ewl_menu_test.c",
  191.             "Defines the basic menu classes that\n"
  192.                 "are extended to an actual menu\n"
  193.                 "implementation by inheriting classes\n"
  194.                 "such as Ewl_Menu and Ewl_IMenu."
  195.         },
  196.         {
  197.             "Menubar",
  198.                 __create_menubar_test_window,
  199.                 "ewl_menubar_test.c",
  200.             "Defines a menubar that can be used to hold menus."
  201.         },
  202.         {
  203.             "Notebook",
  204.                  __create_notebook_test_window,
  205.                  "ewl_notebook_test.c",
  206.             "Provides a container whose children\n"
  207.                 "are pages that can be switched\n"
  208.                 "between using tab labels along one\nedge"
  209.         },
  210.         {
  211.             "Paned",
  212.               __create_paned_test_window,
  213.               "ewl_paned_test.c",
  214.             "Defines the Ewl_Paned to hold two resizable panes."
  215.         },
  216.         {
  217.             "Password",
  218.                  __create_password_test_window,
  219.                  "ewl_password_test.c",
  220.             "Defines the Ewl_Password class to allow\n"
  221.                 "for single line obscured text."
  222.         },
  223.         {
  224.             "Progressbar",
  225.             __create_progressbar_test_window,
  226.             "ewl_progressbar_test.c",
  227.             "Provides a progress bar from a given value."
  228.         },
  229.         {
  230.             "Spinner",
  231.                 __create_spinner_test_window,
  232.                 "ewl_spinner_test.c",
  233.             "Provides a field for entering numerical\n"
  234.                 "values, along with buttons to increment\n"
  235.                 "and decrement the value."
  236.         },
  237.         {
  238.             "Statusbar",
  239.                   __create_statusbar_test_window,
  240.                   "ewl_statusbar_test.c",
  241.             "Provides a statusbar for the window."
  242.         },
  243.         {
  244.             "Table",
  245.               __create_table_test_window,
  246.               "ewl_table_test.c",
  247.             "Defines the Ewl_Table class used for\n"
  248.                 "laying out Ewl_Widget's in an array."
  249.         },
  250.         {
  251.             "Text",
  252.                  __create_text_test_window,
  253.                  "ewl_text_test.c",
  254.             "Defines a class for multi-line text layout\n"
  255.                 "and formatting."
  256.         },
  257.         {
  258.             "Text Editor",
  259.                  __create_text_editor_test_window,
  260.                  "ewl_text_editor_test.c",
  261.             "Defines a class for multi-line text layout\n"
  262.                 "and formatting."
  263.         },
  264.         {
  265.             "Theme",
  266.               __create_theme_test_window,
  267.               "ewl_theme_test.c",
  268.             "Shows the utilization of themes\n"
  269.                 "inside a EWL application."
  270.                },
  271.         {
  272.             "Tooltip",
  273.                 __create_tooltip_test_window,
  274.                 "ewl_tooltip_test.c",
  275.             "Defines a widget for displaying short\n"
  276.                 "messages after a delay."
  277.         },
  278.         {
  279.             "Tree",
  280.              __create_tree_test_window,
  281.              "ewl_tree_test.c",
  282.             "Defines a widget for laying out other\n"
  283.                 "widgets in a tree or list like manner."
  284.         },
  285.         { 0, NULL, 0, NULL }
  286.     };
  287.  
  288.     void *heap_start, *heap_end;
  289.     char *header[1] = {
  290.         "Widgets"
  291.     };
  292.  
  293.     heap_start = sbrk(0);
  294.  
  295.     if (!ewl_init(&argc, argv)) {
  296.         fprintf(stderr, "Could not init ewl. Exiting...\n");
  297.         return 1;
  298.     }
  299.  
  300.     if (argc > 1) {
  301.         int j, found = 0;
  302.  
  303.         for (j = 1; j < argc; j++) {
  304.             for (i = 0; tests[i].func; i++) {
  305.                 if (!strcasecmp(argv[j], tests[i].name)) {
  306.                     tests[i].func(NULL, NULL, NULL);
  307.                     found++;
  308.                 }
  309.             }
  310.         }
  311.  
  312.         if (found) {
  313.             ewl_main();
  314.             exit(0);
  315.         }
  316.     }
  317.  
  318.     heap_end = sbrk(0);
  319.     printf("HEAP SIZE:\t%u bytes\n", heap_end - heap_start);
  320.  
  321.     main_win = ewl_window_new();
  322.     ewl_object_size_request(EWL_OBJECT(main_win), 400, 400);
  323.     ewl_window_title_set(EWL_WINDOW(main_win),
  324.                  "The Enlightenment Widget Library");
  325.     ewl_window_name_set(EWL_WINDOW(main_win), "EWL Test Application");
  326.     ewl_window_class_set(EWL_WINDOW(main_win), "EFL Test Application");
  327.     ewl_callback_append(main_win, EWL_CALLBACK_DELETE_WINDOW,
  328.                 __close_main_window, NULL);
  329.     ewl_callback_append(main_win, EWL_CALLBACK_REALIZE,
  330.                 __realize_main_window, NULL);
  331.     ewl_widget_show(main_win);
  332.  
  333.     /*
  334.      * Create the main box for holding the test scrollpane areas
  335.      */
  336.     main_box = ewl_hbox_new();
  337.     ewl_container_child_append(EWL_CONTAINER(main_win), main_box);
  338.     ewl_box_spacing_set(EWL_BOX(main_box), 6);
  339.     ewl_box_homogeneous_set (EWL_BOX (main_box), FALSE);
  340.     ewl_widget_show(main_box);
  341.  
  342.     main_tree = ewl_tree_new(1);
  343.     ewl_tree_headers_set (EWL_TREE (main_tree), header);
  344.     ewl_container_child_append(EWL_CONTAINER(main_box), main_tree);
  345.     ewl_object_fill_policy_set (EWL_OBJECT (main_tree),
  346.                     EWL_FLAG_FILL_HSHRINK |
  347.                     EWL_FLAG_FILL_VSHRINK |
  348.                     EWL_FLAG_FILL_VFILL);
  349.     ewl_widget_show(main_tree);
  350.  
  351.     /*
  352.     separator = ewl_vseparator_new();
  353.     ewl_container_child_append(EWL_CONTAINER(main_box), separator);
  354.     ewl_widget_show(separator);
  355.     */
  356.  
  357.     main_area = ewl_scrollpane_new();
  358.     ewl_widget_show(main_area);
  359.     ewl_container_child_append(EWL_CONTAINER(main_box), main_area);
  360.  
  361.     main_text = ewl_text_new ();
  362.     ewl_text_text_set(EWL_TEXT(main_text),
  363.                 "  Click on the objects on the left to\n"
  364.                 "show a working example and the source\n"
  365.                 "of the corresponding widget.\n"
  366.                 "Keep the mouse on the button to see\n"
  367.                 "a brief description of the widget.");
  368.     ewl_container_child_append(EWL_CONTAINER(main_area),
  369.                    main_text);
  370.     ewl_widget_show(main_text);
  371.  
  372.     i = 0;
  373.     while (tests[i].func) {
  374.         /*
  375.          * Add the row to the tree, and setup it's alignment and
  376.          * fill.
  377.          */
  378.         prow = ewl_tree_text_row_add( EWL_TREE (main_tree), NULL,
  379.                          &(tests[i].name));
  380.         ewl_callback_append (EWL_WIDGET (prow), 
  381.                      EWL_CALLBACK_CLICKED,
  382.                      EWL_CALLBACK_FUNCTION (tests[i].func), 
  383.                      NULL);
  384.         ewl_callback_append (EWL_WIDGET (prow), 
  385.                      EWL_CALLBACK_CLICKED,
  386.                      EWL_CALLBACK_FUNCTION (__fill_main_text),
  387.                      tests[i].filename);
  388.         
  389.         /* Add the tooltips */
  390.         if (tests[i].tip) 
  391.             ewl_attach_tooltip_text_set(prow, tests[i].tip);
  392.  
  393.         i++;
  394.     }
  395.  
  396.     heap_end = sbrk(0);
  397.     printf("HEAP SIZE:\t%u bytes\n", heap_end - heap_start);
  398.  
  399.     ewl_main();
  400.  
  401.     heap_end = sbrk(0);
  402.     printf("HEAP SIZE:\t%u bytes\n", heap_end - heap_start);
  403.  
  404.     return 0;
  405. }
  406.  
  407.